package com.itheima.test12;

import java.time.Period;

public class Cookie extends Thread{
    private static int count = 0;
    private Desk desk;

    public Cookie(Desk desk) {
        this.desk = desk;
    }

    @Override
    public void run() {
        while (true){
            synchronized (desk){
                if (desk.getCount() == 0){
                    break;
                }else {
                    if (desk.isFlag()){
                        try {
                            desk.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }else {
                        try {
                            desk.wait(100);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        count++;
                        System.out.println("厨师做了一份食物" + count);
                        desk.setFlag(!desk.isFlag());
                        desk.notifyAll();
                    }
                }
            }
        }
    }
}
